package tv.accedo.achi.model;

import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.springframework.stereotype.Component;

@Component
@Entity
@Table(name="t_user")
public class User {

	private int id; //generated by native
	private String username; //unique & not-null
	private long score; // not-null
	private int level; // not-null
	private Set<Achi> achis; //many-to-many
	private Set<Badge> badges; //many-to-many
	private Set<Camp> camps; //many-to-many
	
	@Id
	@GeneratedValue
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	@Column(unique=true,
			nullable=false)
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	
	@Column(nullable=false)
	public long getScore() {
		return score;
	}
	public void setScore(long score) {
		this.score = score;
	}
	
	@ManyToMany(fetch = FetchType.EAGER)
	@JoinTable(name="t_user_achi", 
			joinColumns={@JoinColumn(name="user_id")},
			inverseJoinColumns={@JoinColumn(name="achi_id")})
	public Set<Achi> getAchis() {
		return achis;
	}
	public void setAchis(Set<Achi> achis) {
		this.achis = achis;
	}
	
	@Column(nullable=false)
	public int getLevel() {
		return level;
	}
	public void setLevel(int level) {
		this.level = level;
	}
	
	@ManyToMany(fetch = FetchType.EAGER)
	@JoinTable(name="t_user_badge", 
			joinColumns={@JoinColumn(name="user_id")},
			inverseJoinColumns={@JoinColumn(name="badge_id")})
	public Set<Badge> getBadges() {
		return badges;
	}
	public void setBadges(Set<Badge> badges) {
		this.badges = badges;
	}
	
	@ManyToMany(fetch = FetchType.EAGER)
	@JoinTable(name="t_user_camp", 
			joinColumns={@JoinColumn(name="user_id")},
			inverseJoinColumns={@JoinColumn(name="camp_id")})
	public Set<Camp> getCamps() {
		return camps;
	}
	public void setCamps(Set<Camp> camps) {
		this.camps = camps;
	}
	
}
